package au.com.iglootech.winerymap.entity;

import java.util.Date;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import javax.jdo.annotations.Queries;
import javax.jdo.annotations.Query;
import javax.persistence.Transient;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

/**
 * 
 * @author Nicholas Zhu
 * 
 */
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
@Queries({ @Query(name = WMUser.FIND_BY_USERNAME, value = "SELECT FROM WMUser "
		+ "where username == :pUsername && password == :pPassword && valid != false") })
public class WMUser implements IGTDomainEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = 7402551905880697456L;

	@Transient
	public static final String FIND_BY_USERNAME = "findByUserName";

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Key key;

	@Persistent
	private String username;

	@Persistent
	private String emailAddress;

	@Persistent
	private String password;

	@Persistent
	private Date createdDate;

	@Persistent
	private UserType userType;

	@Persistent
	private String nickName;

	@Persistent
	private Boolean valid = true;

	/**
	 * 
	 * @return username
	 */
	public String getUsername() {
		return username;
	}

	/**
	 * 
	 * @param username
	 *            username
	 */
	public void setUsername(final String username) {
		this.username = username;
	}

	/**
	 * 
	 * @return emailAddress
	 */
	public String getEmailAddress() {
		return emailAddress;
	}

	/**
	 * 
	 * @param emailAddress
	 *            emailAddress
	 */
	public void setEmailAddress(final String emailAddress) {
		this.emailAddress = emailAddress;
	}

	/**
	 * 
	 * @return password
	 */
	public String getPassword() {
		return password;
	}

	/**
	 * 
	 * @param password
	 *            password
	 */
	public void setPassword(final String password) {
		this.password = password;
	}

	/**
	 * 
	 * @return createdDate
	 */
	public Date getCreatedDate() {
		return createdDate;
	}

	/**
	 * 
	 * @param createdDate
	 *            createdDate
	 */
	public void setCreatedDate(final Date createdDate) {
		this.createdDate = createdDate;
	}

	/**
	 * @return the userType
	 */
	public UserType getUserType() {
		return userType;
	}

	/**
	 * @param userType
	 *            the userType to set
	 */
	public void setUserType(final UserType userType) {
		this.userType = userType;
	}

	@Override
	public Key getKey() {
		return key;
	}

	@Override
	public void setKey(final Key key) {
		this.key = key;
	}

	@Override
	public String toLogString() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Key createBy() {
		return null;
	}

	/**
	 * 
	 * @return string of key
	 */
	public String getKeyValue() {
		return KeyFactory.keyToString(key);
	}

	/**
	 * 
	 * @param keyValue
	 *            string of key
	 */
	public void setKeyValue(final String keyValue) {
		key = KeyFactory.stringToKey(keyValue);
	}

	/**
	 * @return the nickName
	 */
	public String getNickName() {
		return nickName;
	}

	/**
	 * @param nickName
	 *            the nickName to set
	 */
	public void setNickName(final String nickName) {
		this.nickName = nickName;
	}

	/**
	 * @return the valid
	 */
	public Boolean getValid() {
		return valid;
	}

	/**
	 * @param valid
	 *            the valid to set
	 */
	public void setValid(final Boolean valid) {
		this.valid = valid;
	}

}
